package com.sbl.bajw.pc.model;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

public class UserGpsModel {
	
	String userid;
	Timestamp lastTime;
	double lastX=0;
	double lastY=0;
	List<GpsModel> gpsModels = new ArrayList<GpsModel>();
	
	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public UserGpsModel(String userid){
		this.userid = userid;
	}
	
	public void add(double x,double y,double speed){
		Timestamp time = new Timestamp((new Date()).getTime());
		lastTime = time;
		
		if(x < 10 || y < 10){
			return;
		}
		
		if(Math.abs(x - lastX) < 0.00002&&Math.abs(y - lastY) < 0.00002){
			return;
		}
		lastX = x;
		lastY = y;
		GpsModel gpsModel = new GpsModel(x,y,speed,time);
		gpsModels.add(gpsModel);
	}
	
	public int getGpsCount(){
		int count = gpsModels.size();
		return count;
	}
	
	public void clear(){
		gpsModels.clear();
	}
	
}

class GpsModel{
	double x;
	double y;
	Timestamp time;
	double speed;
	String gpsid;
	
	public GpsModel(double x,double y,double speed,Timestamp time){
		setX(x);
		setY(y);
		setTime(time);
		setSpeed(speed);
		setGpsid(UUID.randomUUID().toString());
	}
	
	public String getGpsid() {
		return gpsid;
	}

	public void setGpsid(String gpsid) {
		this.gpsid = gpsid;
	}

	public double getSpeed() {
		return speed;
	}

	public void setSpeed(double speed) {
		this.speed = speed;
	}

	public Timestamp getTime() {
		return time;
	}

	public void setTime(Timestamp time) {
		this.time = time;
	}



	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	
	
}